﻿using ServerFramework.Net.Msg;
using System;

namespace MsgDefine
{
    /// <summary>
    /// 三种定义消息方式   可根据 客户端平台选择合适的方式
    /// </summary>
    #region 方式1 序列化为c#自带的序列化方式
    //[Serializable]
    //public class ReqHelloworld :BinaryMsg
    //{
    //    public string ReqString;
    //    protected override void WriteMsgId()
    //    {
    //        _msgId = (int)EMsgID.MSGID_HELLOW_WORLD;
    //    }
    //}

    //[Serializable]
    //public class ResHelloworld : BinaryMsg
    //{
    //    public string ResString;
    //    protected override void WriteMsgId()
    //    {
    //        _msgId = (int)EMsgID.MSGID_HELLOW_WORLD;
    //    }
    //}
    #endregion
    #region 方式2 序列化为使用json
    //public class ReqHelloworld : JsonMsg
    //{
    //    public string ReqString;
    //    protected override void WriteMsgId()
    //    {
    //        _msgId = (int)EMsgID.MSGID_HELLOW_WORLD;
    //    }
    //}

    //public class ResHelloworld : JsonMsg
    //{
    //    public string ResString;
    //    protected override void WriteMsgId()
    //    {
    //        _msgId = (int)EMsgID.MSGID_HELLOW_WORLD;
    //    }
    //}
    #endregion
    #region 方式3 字节流打包方式 通用性好
    public class ReqHelloworld : StreamMsg
    {
        public int id;
        public string ReqString;
        public override void Sn(MsgSn sn)
        {
            sn.Write(id).Write(ReqString);
        }
        public override void Usn(MsgUsn usn)
        {
            usn.Read(ref id).Read(out ReqString);
        }
        protected override void WriteMsgId()
        {
            _msgId = (int)EMsgID.MSGID_HELLOW_WORLD;
        }
    }

    public class ResHelloworld : StreamMsg
    {
        public string ResString;
        public override void Sn(MsgSn sn)
        {
            sn.Write(ResString);
        }
        public override void Usn(MsgUsn usn)
        {
            usn.Read(out ResString);
        }
        protected override void WriteMsgId()
        {
            _msgId = (int)EMsgID.MSGID_HELLOW_WORLD;
        }
    }
    #endregion

}
